<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    //原始类型: number,string,boolean,undefined,null
    //引用类型: object,array,function,date...
    var a = 1;
    var  b = 6.6;
    console.log(a,typeof a,b,typeof b);//整数小数都是number
    var c = 'hello';
    var d = "你好";
    console.log(c,typeof c,d,typeof d);//单引双引都是string
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);//true与false都是布尔类型
    //声明了变量但未赋值,推断不出来数据类型,所以是未定义型undefined
    var g;
    console.log(g,typeof g);//undefined 'undefined'

    //定义一个自定义对象
    let obj = {};
    obj.name = '张三';
    obj.age = 18;
    console.log(obj,typeof obj);//{name: '张三', age: 18} 'object'
    console.log(obj.name,obj.age);//
    //声明自带属性的对象
    let obj2 = {
        name:'李四',
        age:19
    };
    console.log(obj2,typeof obj2);//{name: '李四', age: 19} 'object'
    console.log(obj2.name,obj2.age);
    console.log(obj2.play);//访问不存在的属性,会得到undefined
    //但可以后期动态新增属性!
    obj2.like = '打篮球';
    console.log(obj2);
    console.log(obj2.like);//打篮球

    //JS数组
    let arr = ['张三',16,true,5.5];
    console.log(arr,typeof arr);//['张三', 16, true, 5.5] 'object'
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);//访问数组不存在的下标也是undefined

    //Boolean()用于将参数转为布尔类型
    //0 null NaN undefined '' 转为布尔都是false!
    console.log(Boolean(0));
    console.log(Boolean(undefined));
    console.log(Boolean(null));
    console.log(Boolean(NaN));
    console.log(Boolean(''));
    console.log(Boolean('1'));
    console.log(Boolean('hello'));
    console.log(Boolean(' '));

    //Number()用于将参数转为数字类型
    //如果得不到数字类型的结果,就会得到NaN(Not a Number)
    console.log(Number(true),typeof Number(true));
    console.log(Number(false),typeof Number(false));
    console.log(Number(3),typeof Number(3));
    console.log(Number('3'),typeof Number('3'));
    console.log(Number('哈哈哈'));//NaN(Not a Number)


</script>
</body>
</html>